package com.mall.mallDemo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.mallDemo.exception.ExceptionEnum;
import com.mall.mallDemo.exception.MyException;
import com.mall.mallDemo.mapper.CarouselMapper;
import com.mall.mallDemo.pojo.Carousel;
import com.mall.mallDemo.service.CarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lii
 * @create 2022-06-15 9:05
 */
@Service("carouselService")
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements CarouselService {

    @Autowired
    private CarouselMapper carouselMapper;

    @Override
    public List<Carousel> getCarouselList() {
        List<Carousel> list = null;
        try {
            list = carouselMapper.selectList(null);
            if (ArrayUtils.isEmpty(list.toArray())) {
                throw new MyException(ExceptionEnum.GET_CAROUSEL_NOT_FOUND);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(ExceptionEnum.GET_CAROUSEL_ERROR);
        }
        return list;
    }
}
